package com.hzsai.controller;

import com.github.pagehelper.PageHelper;
import com.hzsai.pojo.AopUser;
import com.hzsai.service.DynamicDSService;
import com.hzsai.utils.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * hzsai 2019/8/28
 * usage:
 **/
@Api(tags = "动态数据源--注解版")
@RestController
@RequestMapping("/dynamicDS")
public class DynamicDSController {

    @Autowired
    private DynamicDSService service;

    @ApiOperation(value = "根据id查询用户")
    @GetMapping("/user/{id}")
    ResultMsg selectById(@PathVariable("id") Integer id) {

        AopUser user = service.selectById(id);

        return user == null ? ResultMsg.error(400, "查询失败，无用户")
                : ResultMsg.success(user);
    }

    @ApiOperation(
            value = "使用PageHelper分页查询用户",
            notes = "参数例子：" +
                    "{\"pageNow\":\"1\", \"pageSize\": \"12\"}"
    )
    @PostMapping("/user/pages")
    ResultMsg selectUserPage(@RequestBody Map<String, Object> params) {
        return ResultMsg.success(service.selectUserPage(params));
    }
}
